<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Hash;

abstract class BaseModel extends Model
{
    const TABLE_NAME = '';

    protected $dateFormat = 'U';

    protected $auto = [];

    protected $scene;

    protected $scene_fields = [];

    const AUTO_TYPE_CALLBACK    = 'callback';
    const AUTO_TYPE_VALUE       = 'value';

    const FIELD_ID              = 'id';
    const FIELD_VERSION         = 'version';
    const FIELD_CREATED_AT      = 'created_at';
    const FIELD_UPDATED_AT      = 'updated_at';
    const FIELD_DELETED_AT      = 'deleted_at';

    public function getCreatedAtAttribute($created_at)
    {
        return date('Y-m-d H:i:s', $created_at);
    }

    public function getUpdatedAtAttribute($updated_at)
    {
        return date('Y-m-d H:i:s', $updated_at);
    }

    public function setPasswordAttribute($password)
    {
        $this->attributes['password'] = Hash::make($password);
    }

    /**
     * 场景设置
     *
     * @param $scene
     */
    protected function setScene($scene)
    {
        $this->scene = $scene;
    }
}
